package com.xidian.zhiancloud.controller.systemset.usermanage;

import com.xidian.zhiancloud.controller.base.BaseController;
import com.xidian.zhiancloud.dto.ResultDTO;
import com.xidian.zhiancloud.enums.GeneralResponseEnums;
import com.xidian.zhiancloud.model.syset.EnterFoundList;
import com.xidian.zhiancloud.service.user.usermanage.EnterFoundService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.Date;

/**
 * 系统设置-企业基础信息设置
 */

@RestController
@RequestMapping("/enterFound")
public class EnterFoundController extends BaseController {

    @Autowired
    EnterFoundService enterFoundService;

    @Autowired
    HttpServletRequest request;

    /**
     * 基础信息显示
     * @return 返回 ResultDTO 对象
     */
    @RequestMapping("/getEnterFoundList")
    public ResultDTO getEnterFoundList(){
        Long companyid = this.getSessionUserCompanyId();
        return ResultDTO.successOf(enterFoundService.getEnterFoundList(companyid),GeneralResponseEnums.SUCCESS);
    }

    /**
     * 企业认证信息
     * @param enterprisename 企业名称
     * @param referred 企业简称
     * @param industry 所属行业分类
     * @param position 企业地址
     * @param positiondetail 企业详细地址
     * @param longitude 经度
     * @param latitude 纬度
     * @return 返回 ResultDTO 对象
     */
    @RequestMapping("/addEFAuthenticationInformation")
    public ResultDTO addEFAuthenticationInformation(
            @RequestParam("enterprisename") String enterprisename,
            @RequestParam("referred") String referred,
            @RequestParam("industry") String industry,
            @RequestParam("position") String position,
            @RequestParam("positiondetail") String positiondetail,
            @RequestParam("longitude") BigDecimal longitude,
            @RequestParam("latitude") BigDecimal latitude){
            Long companyid = this.getSessionUserCompanyId();
            enterFoundService.addEFAuthenticationInformation
             (companyid,enterprisename,referred,industry,position,
              positiondetail,longitude,latitude);
        return ResultDTO.successOf(GeneralResponseEnums.SUCCESS);
    }

    /**
     * 企业证件管理
     * @param id 企业基础信息ID
     * @param certificatename 证书名称
     * @param certificationauthority 发证机构
     * @param validity 有效期
     * @param reviewreminderdate 复审提醒日期
     * @param certificatephoto 证书照片
     * @return 返回 ResultDTO 对象
     */
        @RequestMapping("/updateEFCertificateManagement")
        public ResultDTO updateEFCertificateManagement
            (@RequestParam(value = "id",required = false,
                    defaultValue = "0") String id,
            @RequestParam("certificatename") String certificatename,
            @RequestParam("certificationauthority")
                     String certificationauthority,
            @RequestParam(value = "validity",required = false,
                     defaultValue ="yesterday()") Date validity,
            @RequestParam(value = "reviewreminderdate",required = false,
                     defaultValue ="yesterday()") Date reviewreminderdate,
            @RequestParam("certificatephoto") String certificatephoto){
                enterFoundService.updateEFCertificateManagement
                   (id,certificatename,certificationauthority,
                    validity,reviewreminderdate,certificatephoto);
            return ResultDTO.successOf(GeneralResponseEnums.SUCCESS);
        }

    /**
     * 企业基础信息编辑
     * @param id 企业基础信息ID
     * @param enterfound 企业基础信息体
     * @return 返回 ResultDTO 对象
     */
    @RequestMapping("/updateBasicEnterpriseInformation")
    public ResultDTO updateBasicEnterpriseInformation
          (@RequestParam(value = "id",required = false,defaultValue = "0")
            String id,@RequestBody EnterFoundList enterfound){
        enterFoundService.updateBasicEnterpriseInformation(id,enterfound);
        return ResultDTO.successOf(GeneralResponseEnums.SUCCESS);
    }

}
